from django.shortcuts import render
from .serializers import ContentsSerializer
from .models import Contents
from rest_framework import viewsets, mixins



# Create your views here.
class ContentsViews(viewsets.ModelViewSet):
    serializer_class = ContentsSerializer

    # 显示接口
    def get_queryset(self):
        return Contents.objects.all()

    # 删除接口
    def destory(self, request, pk=None):
        obj = Contents.objects.get(id=pk)
        obj.delete()

    # 添加接口
    def create(self, request):
        serializer = ContentsSerializer(data=request.data)
        serializer.is_valid(raise_exception=True)
        serializer.save()
        return Response(serializer.data)

